package c.c.b.a.a;

/* compiled from: Segment */
public final class s {
    public final byte[] a;
    public int b;
    public int c;
    public boolean d;
    public boolean e;
    public s f;
    public s g;

    public s() {
        this.a = new byte[8192];
        this.e = true;
        this.d = false;
    }

    public final s a() {
        this.d = true;
        return new s(this.a, this.b, this.c, true, false);
    }

    public final s b(s sVar) {
        sVar.g = this;
        sVar.f = this.f;
        this.f.g = sVar;
        this.f = sVar;
        return sVar;
    }

    public final void c(s sVar, int i) {
        if (sVar.e) {
            int i2 = sVar.c;
            if (i2 + i > 8192) {
                if (sVar.d) {
                    throw new IllegalArgumentException();
                }
                int i3 = i2 + i;
                int i4 = sVar.b;
                if (i3 - i4 <= 8192) {
                    byte[] bArr = sVar.a;
                    System.arraycopy(bArr, i4, bArr, 0, i2 - i4);
                    sVar.c -= sVar.b;
                    sVar.b = 0;
                } else {
                    throw new IllegalArgumentException();
                }
            }
            System.arraycopy(this.a, this.b, sVar.a, sVar.c, i);
            sVar.c += i;
            this.b += i;
            return;
        }
        throw new IllegalArgumentException();
    }

    public final s d() {
        s sVar = this.f;
        s sVar2 = sVar != this ? sVar : null;
        s sVar3 = this.g;
        sVar3.f = sVar;
        this.f.g = sVar3;
        this.f = null;
        this.g = null;
        return sVar2;
    }

    public s(byte[] bArr, int i, int i2, boolean z, boolean z2) {
        this.a = bArr;
        this.b = i;
        this.c = i2;
        this.d = z;
        this.e = z2;
    }
}
